package com.example.demo.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * jdk8串行和并行
 */
public class DemoParalleStream {
    public static void main(String[] args) {
        //串行
        //初始化值
        int num = 10000000;
        List<String> vas = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {

            UUID uuid = UUID.randomUUID();
            vas.add(uuid.toString());
        }

        //串行计算 14433
        long start = System.currentTimeMillis();
        long vasCount = vas.stream().sorted().count();
        long end = System.currentTimeMillis();
        long time = end - start;
        System.out.println(time);

        //并行计算 9301
        long start2 = System.currentTimeMillis();
        long vasCount2 = vas.parallelStream().sorted().count();
        long end2 = System.currentTimeMillis();
        long time2 = end2 - start2;
        System.out.println(time2);

    }
}
